$(document).ready(function(){ 

	
	$.extend($.validator.prototype,{
				showLabel: function(element, message) {
					var inputName = $(element).attr("name");
					var spanObj = $("#" + inputName + "_p");
					spanObj.html("");
					// 验证失败的时候
					if (message) {
						spanObj.attr("class", "qygs_qinp2");
						spanObj.html('<img src="images/error_ts.png" style="vertical-align:middle;"/> '
										+ message);
					} else {
						spanObj.html("");
						spanObj.attr("class", "");
//						spanObj.html('<img src="images/onSuccess.png" style="vertical-align:middle;"/> ');
					}
				}
			});
	
	jQuery.validator.addMethod("Chinese", function(value, element) {
		var china=/^[\u4E00-\u9FA5]+$/.test(value);
		
		return this.optional(element) ||china;
	},"");
	
	jQuery.validator.addMethod("idFormat", function(value, element) {
		var idReg = /^((1[1-5])|(2[1-3])|(3[1-7])|(4[1-6])|(5[0-4])|(6[1-5])|71|(8[12])|91)\d{4}((19\d{2}(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(19\d{2}(0[13578]|1[02])31)|(19\d{2}02(0[1-9]|1\d|2[0-8]))|(19([13579][26]|[2468][048]|0[48])0229))\d{3}(\d|X|x)?$/;
		if (!idReg.test(value)) {
			return false;
		}
		return this.optional(element) || true;
	},
	"");
	
	// 日期格式验证
	jQuery.validator.addMethod("date", function(value, element) { 
	  var tel = /^\d{4}-?\d{2}-?\d{2}$/; //日期格式 1988-07-15
	  return this.optional(element) || (tel.test(value)); 
	}, ""); 
	
	
	//表单提交验证js
	$("#huiyuanForm").validate({ 
	 success: true,
	 focusInvalid: true,
     rules:{ 
    	 	
    	 	shengao:{
    	 		required:true,
    	 		number:true
    	 	},
    	 	thebirthday:{
    	 		required:true,
    	 		date:true
    	 	},
    	 	tizhong:{
    	 		required:true,
    	 		number:true
    	 	},
    	 	fenshu:{
    	 		required:true,
    	 		number:true
    	 	},
    	 	idcard:{
	     		required:true,
				idFormat:true
	     	}
        },
	    messages:{
	    	shengao:{
	    		required:"身高为必填",
	    		number:"必须为数字"
    	 	},
    	 	thebirthday:{
    	 		required:"日期为必填项",
    	 		date:"日期格式错误"
    	 	},
    	 	tizhong:{
	    		required:"体重为必填",
	    		number:"必须为数字"
    	 	},
    	 	fenshu:{
	    		required:"评分为必填",
	    		number:"必须为数字"
    	 	},
    	 	idcard:{
	    		required:"身份证号不能为空",
				idFormat:"身份证格式不正确"
	    	}
    	 	
    	}	
    });
	
$("#tijiao").click(function() {
		
		var resultFlag = $("#huiyuanForm").valid();
			
		if (resultFlag) {
			$("#huiyuanForm").submit();
		}
	});	
	

	
		
});